//
//  GLBottomView.m
//  GLSliderView
//
//  Created by 张国梁 on 15/11/28.
//  Copyright © 2015年 CoderGL. All rights reserved.
//

#import "GLBottomView.h"

#define Margin 40
#define Columns 3

@interface GLBottomView ()
@property (nonatomic, strong) NSArray *images;
@property (nonatomic, strong) NSArray *names;

@end


@implementation GLBottomView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.images = @[@"pluginboard_icon_comment", @"pluginboard_icon_favor", @"pluginboard_icon_comment", @"pluginboard_icon_favor", @"pluginboard_icon_comment", @"pluginboard_icon_favor", @"pluginboard_icon_comment", @"pluginboard_icon_favor"];
        
        [self.images enumerateObjectsUsingBlock:^(NSString *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            UIButton *btn = [UIButton new];
            [btn setBackgroundImage:[UIImage imageNamed:obj] forState:UIControlStateNormal];
            [btn setTitle:idx % 2 == 0 ? @"美女" : @"帅哥" forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont systemFontOfSize:14];
            btn.titleEdgeInsets = UIEdgeInsetsMake(25, 0, 0, 0);
            
            btn.showsTouchWhenHighlighted = YES;
            
//            [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:btn];
        }];
    }
    return self;
}

- (void)layoutSubviews {
    [self.subviews enumerateObjectsUsingBlock:^(__kindof UIButton * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        obj.size = obj.currentBackgroundImage.size;
        obj.x = Margin + idx % Columns * (obj.width + Margin);
        obj.y = Margin + idx / Columns * (obj.height + Margin);
        
    }];
}



@end
